home *** CD-ROM | disk | FTP | other *** search
- {******************************************************************}
- { }
- { Mancala }
- { Turbo Pascal for Windows }
- { Copyright (c) 1991 by Swan Software. All rights reserved. }
- { }
- {******************************************************************}
-
- { uplay.pas -- Play action for Mancala }
-
- unit UPlay;
-
- interface
-
- uses UGlobals, Idents;
-
- procedure NewGame(var Side: Integer);
- function GetMove(Side: Integer; var Move: OneMove): Boolean;
- procedure PrepareReplay(Move: OneMove);
-
-
- implementation
-
- uses WinTypes, WinProcs, WObjects, UMove, USearch;
-
-
- {- Save information required for instant replay }
-
- procedure PrepareReplay(Move: OneMove);
- begin
- ReplayBoard := MainPosition;
- ReplayMove := Move;
- ReplaySide := Side;
- ReplayOk := true;
- end;
-
-
- {- Reinitialize global variables and display for a new game. }
-
- procedure Newgame(var Side: Integer);
- var
- I: Integer;
- begin
- Side := Human;
- CurrentMessage := Its_your_move;
- HumanMove := -1;
- SelfPlay := false;
- ReplayOk := false;
- with MainPosition do
- begin
- Win := false;
- GoAgain := false;
- for I := 0 to MaxCupIndex do
- Gameboard[I] := PebblesPerCup;
- Gameboard[CompKalah] := 0;
- Gameboard[HumanKalah] := 0;
- end;
- PebblesDiv2 := ((MaxCups - 2) * PebblesPerCup) div 2;
- InvalidateRect(Application^.MainWindow^.HWindow, nil, true);
- end;
-
-
- {- Return true if Move returned for selected Side. If Side = computer,
- then GetMove carries out a search for the best move. If Side = human,
- then GetMove checks that the currently selected cup is legal. }
-
- function GetMove(Side: Integer; var Move: OneMove): Boolean;
- var
- MoveList: ListRec;
- Score: Integer;
- Msg: TMsg;
- begin
- GetMove := false;
- MoveIndex := 0;
- if Side = computer then
- begin
- MoveGen(MainPosition, 1, MoveList);
- if MoveList.Count <> 0 { Computer has at least one move } then
- begin
- BestMove := MoveStack[MoveList.FirstIndex].Move;
- MaxMoveIndex := 0; { Used for debugging move search }
- if (MaxPly > 0) and (MoveList.Count > 1) then
- begin
- LowLevel := 1;
- Search(MainPosition, LowLevel, Score, MoveList, -maxint, +maxint);
- end;
- Move := BestMove;
- GetMove := true;
- {- Delete pending mouse and keyboard messages received during search }
- while PeekMessage(Msg, 0, wm_MouseFirst, wm_MouseLast, pm_Remove) do ;
- while PeekMessage(Msg, 0, wm_KeyFirst, wm_KeyLast, pm_Remove) do ;
- end;
- end else
- if HumanMove <> -1 then
- begin
- Move := HumanMove;
- HumanMove := -1;
- MoveGen(MainPosition, 0, MoveList);
- if MoveList.Count = 0 then Exit; { Human has no legal moves }
- if LegalMove(Move, MoveList) then
- GetMove := true
- end;
- end;
-
-
- end.
-
-
- { ----------------------------------------------------------------
- Copyright (c) 1991 by Swan Software. All rights reserved.
- Revision 1.00 Date: 8/21/1991
- ---------------------------------------------------------------- }
-